<?php
/**
 * Anniversary.php
 * 文件描述 纪念日控制器
 * Created on 2020/8/31 11:46
 * Created by 刘小龙 595929049@qq.com
 */

namespace app\xiangji\controller;


use app\Request;
use app\xiangji\BaseController;
use app\common\helpers\Response;
use app\xiangji\services\UserSignService;
use think\App;
use think\exception\ValidateException;
use app\common\validates\UserSign as UserSignValidate;

class UserSign extends BaseController
{
    private $userSignService;

    public function __construct(UserSignService $userSignService)
    {
        $this->userSignService = $userSignService;
    }

    public function dailySign()
    {
        $result = $this->userSignService->dailySign();
        return $this->success($result);
    }

    public function kiss()
    {
        $result = $this->userSignService->kiss1kiss();
        return $this->success($result);
    }

    public function hug()
    {
        $result = $this->userSignService->hug1hug();
        return $this->success($result);
    }

    /**
     * @todo 查询连续签到天数
     * @return \think\response\Json
     */
    public function continueSignDays()
    {
        $result = $this->userSignService->continueSignDays();
        return $this->success($result);
    }

    /**
     * @todo 查询今日签到状态
     * @return \think\response\Json
     */
    public function todaySignStatus()
    {
        $result = $this->userSignService->showTodaySignStatus();
        return $this->success($result);
    }

    /**
     * @todo 查询月签到数据
     * @param Request $request
     * @return \think\response\Json
     */
    public function queryMothSignData(Request $request)
    {
        try {
            // 校验数据
            validate(UserSignValidate::class)->scene('month_sign')->check($request->get());
            $result = $this->userSignService->queryMonthSignData($request);
            return $this->success($result);
        }catch (ValidateException $exception){  // 数据校验未通过，返回错误信息
            return $this->failed($exception->getError(), Response::HTTP_BAD_REQUEST);
        }
    }
}
